package cn.gok.util;


import jdk.internal.util.xml.impl.Input;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


import java.io.IOException;
import java.io.InputStream;


/**
 * @ClassName MybatisUtils
 * @Description TODO
 * @Author HP
 * @Date 9:59 2022/7/15
 * @Version 1.0
 **/
public class MybatisUtils {
    private static SqlSessionFactory factory = null;
    static {
        try {
            String config="mybatisConfig.xml";
            InputStream is =Resources.getResourceAsStream(config);
            factory= new SqlSessionFactoryBuilder().build(is);
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static SqlSession getSqlSession() {
        SqlSession sqlSession = null;
        if (factory != null) {
            sqlSession = factory.openSession();
            return sqlSession;
        }
        return null;
    }


}

